package gva

import (
	"gin-bms/cmd/datas"
	"gin-bms/core"
	"gin-bms/global"
	"gin-bms/initialize"
	"fmt"
	"github.com/spf13/cobra"
)

var initDbCmd = &cobra.Command{
	Use:   "initdb",
	Short: "gin-bms初始化数据",
	Long: `gin-bms初始化数据视频情况：
	1. mysql完美适配`,
	Run: func(cmd *cobra.Command, args []string) {
		path, _ := cmd.Flags().GetString("path")
		fmt.Printf("%v",path)
		global.GLOBAL_Viper = core.Viper(path) //配置
		global.GLOBAL_LOG = core.Zap()         //日志
		db := initialize.GormMySql()           //初始化数据库
		switch global.GLOBAL_CONFIG.System.DbType {
		case "mysql":
			datas.InitMysqlTables(db)
			datas.InitMysqlData(db)
		default:
			datas.InitMysqlTables(db)
			datas.InitMysqlData(db)
		}
	},
}

func init() {
	rootCmd.AddCommand(initDbCmd)
	initDbCmd.Flags().StringP("path", "p", "config.yaml", "自定配置文件路径(相对路径)")
	initDbCmd.Flags().StringP("frame", "f", "gin", "可选参数为gin,,,") //gf:GoFrame
	initDbCmd.Flags().StringP("type", "t", "mysql", "可选参数为mysql,,,")
}
